<?php
namespace app\member\controller;

class Index extends Member
{

    /**
     * 主页面    2017-10-15
     */
    public function index()
    {
        if (UID) {
            return $this->fetch();
        } else {
            return $this->redirect('User/login');
        }
    }

    /**
     * 修改密码  2017-10-15
     */
    public function changepasswd()
    {
        if (request()->isPost()) {
            $password = input('post.oldpasswd');
            $data['password'] = input('post.newpasswd');
            $repassword = input('post.confirmpasswd');
            if ($data['password'] !== $repassword) {
                return array('ret' => 0, 'msg' => '您输入的新密码与确认密码不一致');
            }
            if (strlen($data['password']) < 6) {
                return array('ret' => 0, 'msg' => '新密码的长度不能小于6位');
            }
            $Login = new \wechat\Login();
            $res = $Login->updateinfo(LID, $password, $data);
            if ($res > 0) {
                return array('ret' => 1, 'msg' => '修改密码成功！');
            } else {
                return array('ret' => 0, 'msg' => '更新密码出错');
            }
        } else {
            return $this->fetch();
        }
    }

    /**
     * 主页面    2017-10-15
     */
    public function home()
    {
        if (UID) {
            $loginer = db(\tname::system_loginer)->find(LID);
            $this -> assign('loginer',$loginer);
            return $this->fetch();
        } else {
            return $this->redirect('User/login');
        }
    }

}